<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面向对象</title>
</head>

<body>

</body>
<script>
    /*     // 1、原型继承
        function Animal() {
            this.colors = ["white", "red", "black"]
        }
        function Cat(name, age) {
            this.name = name;
            this.age = age;
        }
        Cat.prototype = new Animal()
        let tom = new Cat("tom",12)
        tom.colors.push("green")
    
        let marry = new Cat("marry",13)
        console.log(tom);
        console.log(marry); */

    /*     // 2、盗用构造函数
        function Animal(type) {
            this.colors = ["white", "red", "black"]
            this.type = type
        }
        function Cat(name, age, type = "Cat") {
            Animal.call(this, type)
            this.name = name;
            this.age = age;
        }
        Cat.prototype = new Animal()
        let tom = new Cat("tom", 12)
        tom.colors.push("green")
    
        let marry = new Cat("marry", 13)
        console.log(tom);
        console.log(marry);
        console.log(tom instanceof Cat);
        console.log(tom instanceof Animal);
         */
    // 3、结合使用
    function Animal(type) {
        this.colors = ["white", "red", "black"]
        this.type = type
    }
    Animal.prototype.say = function () {
        console.log(123, this.type);
    }
    function Cat(name, age, type = "Cat") {
        Animal.call(this, type)
        this.name = name;
        this.age = age;
    }
    // Cat.prototype.constructor = Cat
    Cat.prototype = new Animal()

    let tom = new Cat("tom", 12)
    tom.colors.push("green")
    let marry = new Cat("marry", 13)
    console.log(tom);
    console.log(marry);
    tom.say();
    console.log(tom instanceof Cat);
    console.log(tom instanceof Animal);

</script>

</html>